/*
 * TablePlayers.fx
 *
 * Created on Apr 26, 2009, 7:17:54 PM
 */

package com.dg.gaming.client.fx.gui;

import com.dg.gaming.api.common.PlayerList;
import com.dg.gaming.client.fx.gui.FXMain;
import java.lang.Object;
import java.util.Observable;
import java.util.Observer;
import javafx.ext.swing.SwingList;
import javafx.ext.swing.SwingListItem;
import javafx.ext.swing.SwingScrollPane;
import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;

/**
 * @author dito
 */

public class TablePlayers extends CustomNode,Observer {
  public var players:PlayerList;
  public var mainframe:FXMain;
  public var list=SwingList{items:[
        ]};

    var scrollpane = SwingScrollPane{ height: 165 scrollable: true
         view: list
    };

    public function setUp(mainframe:FXMain){
        this.mainframe=mainframe;
        setPlayers(mainframe.conn.getTable().getPlayerList());
    }
    var group = Group {
        content: [
             scrollpane
        ]
    }

    public override  function create():Node {
        return group;
    }
  public function setPlayers( players:PlayerList)
  {
        this.players= players;
         this.players.addObserver(this);
        for( item in list.items){
            delete item from list.items;
        }
    for( item in players.getPlayersSortedBySeat()){
            var sw = SwingListItem {
                text: item.toString()
                value:item;
             };

            insert  sw into list.items;
        }

       
  }

  
    public override function update(arg0:Observable , arg1:Object ) {
        setPlayers(players);
    }
   
}
